package com.home.admin.monitor;

import com.home.common.annotation.CheckApiClient;
import com.home.common.constants.client.ClientConstant;
import com.home.common.constants.log.LogTypeConstant;
import com.home.common.constants.log.OperStatusConstant;
import com.home.common.framework.core.controller.BaseController;
import com.home.webapp.monitor.entity.BaseOperLog;
import com.home.webapp.monitor.service.BaseOperLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.format.DateTimeFormatter;


/**
 * Description: 操作日志记录 controller
 * Created by 王大宸 on 2020-10-12 22:27:31
 * Created with IntelliJ IDEA.
 */
@Controller
@RequestMapping(value = "/monitor/oper/log")
@CheckApiClient(title = "操作日志", clientId = ClientConstant.CLIENT_WEB)
public class BaseOperLogController extends BaseController<BaseOperLogService, BaseOperLog, String> {
    private static final Logger logger = LoggerFactory.getLogger(BaseOperLogController.class);

    private static final String PATH_PREFIX = "monitor/log";

    /***
     * 功能描述：跳转到信息管理界面
     *
     * @author 王大宸
     * @date 2020-10-12 22:27:31
     * @param
     * @return java.lang.String
     */
    @GetMapping(value = "/index")
    @RequiresPermissions("monitor:baseOperLog:index")
    public String index() {
        return PATH_PREFIX + "/index";
    }

    /***
     * 功能描述：跳转到查看页面
     *
     * @author 王大宸
     * @date 2020-10-12 22:27:31
     * @param id          需要查看数据的id
     * @param modelMap    modelMap
     * @return java.lang.String
     */
    @GetMapping(value = "/see/{id}")
    @RequiresPermissions("monitor:baseOperLog:see")
    public String see(@PathVariable("id") String id, ModelMap modelMap) throws Exception {
        BaseOperLog operLog = baseService.getById(id);
        operLog.setStatus(OperStatusConstant.getOperStatus(operLog.getStatus()));
        operLog.setBusinessType(LogTypeConstant.getLogType(operLog.getBusinessType()));
        modelMap.put("time", operLog.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        modelMap.put("baseOperLog", operLog);
        return PATH_PREFIX + "/see";
    }

}